<template>
  <ArmyPanelLayout class="barracksLeftTwo" title="实时温湿度">
    <div class="barracksLeftTwo--table" v-if="tableData.length">
      <div class="barracksLeftTwo--table__header row">
        <div class="th one">仓库名称</div>
        <div class="th two">温度</div>
        <div class="th three">温度采集时间</div>
        <div class="th four">湿度</div>
        <div class="th five">湿度采集时间</div>
      </div>
      <div class="barracksLeftTwo--table__body">
        <el-scrollbar wrap-style="overflow:hidden" view-style="height: 365px;overflow: hidden;" :always="false">
          <div class="tablelist">
            <div class="row" :class="{'two': (index % 2 !== 0)}" v-for="(item, index) in tableData" :key="index">
              <div class="row--item one" :title="item.houseName">{{item.houseName}}</div>
              <div class="row--item two" :class="{redcolor: item.tempRedAlarm}" :title="item.tempValue">{{item.tempValue || '--'}}</div>
              <div class="row--item three" :title="item.tempTime">{{item.tempTime || '--'}}</div>
              <div class="row--item four" :class="{redcolor: item.humRedAlarm}" :title="item.humValue">
                <span>{{item.humValue}}</span>
              </div>
              <div class="row--item five" :title="item.humTime">{{item.humTime || '--'}}</div>
            </div>
          </div>
        </el-scrollbar>
      </div>
    </div>
    <div v-else class="empty">
      <DataEmptyTwo></DataEmptyTwo>
    </div>
  </ArmyPanelLayout>
</template>

<script>
import ArmyPanelLayout from '@/views/armyScreen/comp/ArmyPanelLayout.vue'
import {tempAndHumInfoService} from '@/api/armyScreenApiV2.js'
import {random14} from '@/util/utils.js'
import {ElScrollbar} from 'element-plus'
import DataEmptyTwo from "@/components/common/DataEmptyTwo.vue";
import useCommonMethods from "@/mixin/useCommonMethods";
import $bus from "@/util/bus";

export default {
  components: {
    DataEmptyTwo,
    ElScrollbar,
    ArmyPanelLayout,
  },
  data() {
    return {
      sid: 'chart_' + random14(),
      tabList: [],
      tabActive: '',
      tableData: []
    }
  },
  setup () {
    const {dictByTypeService} = useCommonMethods()
    return {
      dictByTypeService
    }
  },
  async mounted() {
    this.getTempAndHumInfo()
    $bus.on('reRequest', this.getTempAndHumInfo)
  },
  beforeUnmount() {
    $bus.off('reRequest', this.getTempAndHumInfo)
  },
  methods: {
    /**
     * 将后台返回的日期 格式化
     * @param dateStr {string} 日期字符串
     */
    transformDate (dateStr) {
      if (dateStr) {
        return dateStr.substring(0, 10) + ' ' +dateStr.substring(11, 20)
      } else {
        return null
      }
    },
    tabChangeAction (value) {
      this.tabActive = value
      this.getTempAndHumInfo()
    },
    getTempAndHumInfo() {
      const paramObj = {
        "valueType": 1
      }
      tempAndHumInfoService(paramObj).then(res => {
        // console.log(res)
        // debugger
        this.tableData = res?.data || []
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.barracksLeftTwo {
  width: 439px;
  height: 460px;
  background-image: none;
  backdrop-filter: blur(10px);

  &--table {
    width: 420px;
    margin: 0 auto;
    margin-top: 16px;
    .row {
      height: 28px;
      line-height: 28px;
      display: flex;
      div{
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis
      }
      .one {
        padding-left: 12px;
        //flex: 1;
        min-width: 80px;
      }

      .two {
        width: 60px;
      }

      .three {
        //width: 130px;
        flex: 1;
      }

      .four {
        width: 60px;
      }
      .five {
        //width: 130px;
        flex: 1;
      }
    }

    &__header {
      display: flex;
      height: 28px;
      line-height: 28px;
      background: rgba(21, 77, 160, 0.20);
      font-family: PingFangSC-Regular;
      font-size: 12px;
      color: #D8F0FF;
      letter-spacing: 0;
      font-weight: 400;
    }

    &__body {
      .tablelist{
        width: 100%;
        animation: move 17s linear infinite normal;
        overflow-x: hidden;
        &:hover{
          animation-play-state:paused;
        }
      }
      .row {
        &.two {
          background-image: url('@/assets/images/armyScreen/通行记录_底纹@2x.png');
          background-size: cover;
        }
        font-family: PingFangSC-Regular;
        font-size: 14px;
        color: rgba(216, 240, 255, 0.80);
        letter-spacing: 0;
        font-weight: 400;
        .row--item{
          &.two{
            color: #00E279;
          }
          &.four{
            color: rgba(50,197,255,0.80);
          }
          &.redcolor{
            color: red;
          }
        }
      }
    }
  }

  .empty {
    width: 100%;
    height: 200px;
  }

  @keyframes move {
    0% {
      transform: translateY(0);
    }
    100% {
      transform: translateY(calc(-100% + 365px));
    }
  }
}
</style>
